package com.cheng.student.controller.servlet;

import com.cheng.student.service.StudentServiceImpl;
import com.cheng.student.utils.Util;

import javax.persistence.criteria.CriteriaBuilder;
import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.util.regex.Pattern;

@WebServlet(name = "getStudentFullsServlet", value = "/getStudentFullsServlet")
public class getStudentFullsServlet
        extends HttpServlet
{
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException
    {
        doPost(request,response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException
    {
        String startS = request.getParameter("start");
        String endS = request.getParameter("end");
        int start = 0;
        int end = 0;
        //合理性校验，不合理空响应体
        if(startS == null||endS == null||"".equals(startS)||"".equals(endS))
        {
            return;
        }
        try
        {
            start = Integer.parseInt(startS);
            end = Integer.parseInt(endS);
        }
        catch (Exception e)
        {
            return;
        }
        if (start < 0 || end < 0 || end < start)
        {
            return;
        }
        String jsonOfStudentFull = new StudentServiceImpl().getJsonOfStudentFull(start, end);

        response.getWriter().write(jsonOfStudentFull);

    }
}
